package com.zlm.common.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 薪资周期
 * @Author: duyufu
 * @Date: 2019/4/25 17:29
 */
public enum StdSalLoopEnum {
            
    SAL_LOOP_YS(0,"元/时"),
    SAL_LOOP_YT(1,"元/天"),
    SAL_LOOP_YZ(2,"元/周"),
    SAL_LOOP_YY(3,"元/月"),
    SAL_LOOP_YN(4,"元/年");


    private Integer code;
    private String name;


    private StdSalLoopEnum(Integer code, String name){
        this.code=code;
        this.name=name;
    }

    //把枚举转成json
    public static String getJsonString(){
        StringBuilder builder = new StringBuilder("{");
        for(StdSalLoopEnum stdSalLoopEnum:StdSalLoopEnum.values()){
            builder.append("\""+stdSalLoopEnum.getCode()+"\":\""+ stdSalLoopEnum.getName()+"\",");
        }
        String json=builder.substring(0, builder.length()-1)+"}";
        return json;
    }

    public static List getStdSalLoop(){
        List list = new ArrayList();
        Map<String,Object> map;
        for(StdSalLoopEnum stdSalLoopEnum:StdSalLoopEnum.values()){
            map= new HashMap<String, Object>();
            map.put("code", stdSalLoopEnum.getCode());
            map.put("name", stdSalLoopEnum.getName());
            list.add(map);
        }
        return list;
    }

    public static String getNameByCode(Integer code){
        for(StdSalLoopEnum stdSalLoopEnum:StdSalLoopEnum.values()){
            if(code.equals(stdSalLoopEnum.getCode())){
                return stdSalLoopEnum.getName();
            }
        }
        return null;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

}
